package com.example.mqspring.rabiitmqbasicleverone.rabbitmqProperties;

import com.example.mqspring.utils.RabbitMqUtil;
import com.google.common.collect.Maps;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.Date;
import java.util.Map;

public class Producer {

    static private String message = "i want some money";

    public AMQP.BasicProperties configChannel(Channel channel, String queue) throws Exception {
        channel.queueDeclare(queue, false, false, false, null);
        Map<String, Object> headermap = Maps.newHashMap();
        headermap.put("key1","value1");
        headermap.put("key2",50);
        headermap.put("key3",false);
        headermap.put("key4","value4");
        AMQP.BasicProperties myproperties = new AMQP.BasicProperties().builder()
                .timestamp(new Date())
                .contentType("text/plain")
                .userId("guest")
                .appId("app id: 20")
                .deliveryMode(1)
                .priority(1)
                .headers(headermap)
                .clusterId("clusterID is: 1")
                .build();
        return myproperties;
    }

    public static void main(String[] args) {
        Producer producer = new Producer();
        Connection connection = RabbitMqUtil.createConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            AMQP.BasicProperties basicProperties = producer.configChannel(channel, RabbitMqUtil.queue);
            //发送消息
            channel.basicPublish("",RabbitMqUtil.queue,basicProperties,message.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
